package com.chuanyang.driverh.utils.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.animation.Interpolator;
import android.widget.Scroller;

import java.lang.reflect.Field;

/**
 * 相思无用，唯别而已。别期若有定，千般煎熬又何如，莫道黯然销魂，何处柳暗花明。
 * @author Fsl
 * viewPager的切换动画的设置
 * created at 2016/10/10 13:39
 */
public class ViewPagerScroller extends Scroller {
	private int mScrollDuration = 2000;            
    
    public void setScrollDuration(int duration){
        this.mScrollDuration = duration;
    }
      
    public ViewPagerScroller(Context context) {
        super(context);
    }
  
    public ViewPagerScroller(Context context, Interpolator interpolator) {
        super(context, interpolator);
    }
  
    public ViewPagerScroller(Context context, Interpolator interpolator, boolean flywheel) {
        super(context, interpolator, flywheel);
    }
  
    @Override
    public void startScroll(int startX, int startY, int dx, int dy, int duration) {
        super.startScroll(startX, startY, dx, dy, mScrollDuration);
    }
  
    @Override
    public void startScroll(int startX, int startY, int dx, int dy) {
        super.startScroll(startX, startY, dx, dy, mScrollDuration);
    }
  
      
      
    public void initViewPagerScroll(ViewPager viewPager) {
        try {
            Field mScroller = ViewPager.class.getDeclaredField("mScroller");
            mScroller.setAccessible(true);
            mScroller.set(viewPager, this);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}
